We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Difference Between LEVEL_NO_RENDER And $this->view->disable()

I'm beginner with Phalcon and I'm currently trying to understand it. If I want to make a method for responing ajax request, what is the corrent way to disable the view rendering. Use:

  1. $this->view->setRenderLevel(View::LEVEL_NO_RENDER ) or
  2. $this->view->disable()

What is the diffrence between them? Thank you



77.7k
Accepted
answer
edited Nov '15

Using View::disable will not trigger the view:afterRender event and should be a tidbit faster, it simply returns the raw output of the action: https://github.com/phalcon/cphalcon/blob/phalcon-v2.0.8/phalcon/mvc/view.zep#L759

Whereas View:::setRenderLevel(View::LEVEL_NO_RENDER) will still trigger the event and also perform addition checks: https://github.com/phalcon/cphalcon/blob/phalcon-v2.0.8/phalcon/mvc/view.zep#L845

The speed difference is neglectable though